// pages/chet/chet.js
const db = wx.cloud.database().collection('chat')
Page({

  data: {
    text: '',
    value: '',
    chatlist: []
  },

  onShow: function () {
    this.getData ()
  },
  getData () { // 获取数据
    let thiss = this
    db.get({
      success (res) {
        console.log(res.data)
        thiss.setData({
          listData:res.data
        })
      }
    })
  },
  handleChat () {
    wx.showLoading({
      title: "稍等...." ,
      mask: true,
  });
    let thiss = this
    db.add({
      data: {
        username:wx.getStorageSync("userInfo").nickName,
        image:wx.getStorageSync("userInfo").avatarUrl,
        chattext:thiss.data.text
      },
      success (res) {
        console.log(res)
        thiss.setData ({
          value:' '
        })
        wx.hideLoading();
      },
      fail (err) {
        console.log(err)
      }
    })
  },
  chatText (data) {
    this.setData ({
      text: data.detail.value
    })
  }
})